import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login/login'
Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path:'/',
   redirect: '/tab'
  },
  {
    path: '/tab',
    component: ()=>import('../layout/tabLayout'),
    children:[
      {
        path:'/home',
        component:()=>import('../views/home/home'),
        meta:{
          title:'主页'
        }
      },
      {
        path:'/classify',
        component:()=>import('../views/classify/classify'),
        meta:{
          title:'分类'
        }
      },
      {
        path:'/shopping',
        component:()=>import('../views/shopping/shopping'),
        auth:true,
        meta:{
          title:'购物车'
        }
      },
      {
        path:'/my',
        component:()=>import('../views/my/my'),
        auth:true,
        meta:{
          title:'我的'
        }
      }
    ]
  },
  {
    path: "/detail/:id",
    name: "detail",
    component: () => import('../views/detail/detail.vue')
  },
  {
    path: "/search",
    component: () => import('../views/search/index.vue')
  },
  {
    path: "/geolocation",
    component: () => import('../views/geolocation/index.vue')
  },
  {
    path: "/address",
    component: () => import('../views/address/index.vue')
  },
  {
    path: "/edit/address",
    component: () => import('../views/editaddress/index.vue')
  },
  {
    path: "/map/location/:cityId",
    component: () => import('../views/mapLoaction')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// router.beforeEach((to, from, next) => {
//   if(to.meta.auth){
//     if('登陆'){
//       next()
//     }else{
//       next('/login')
//     }
//   }else{
//     next()
//   }
// })
router.afterEach( (to) => {
 document.title=to.meta.title
  
})

export default router
